home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / ear / mui23dev.lha / MUI / Developer / C / Examples / AppWindow.c next >
C/C++ Source or Header  |  1994-12-23  |  3KB  |  138 lines

  1. #include "demo.h"
  2.  
  3.  
  4. /*
  5. ** App message callback hook. Note that the object given here
  6. ** is the object that called the hook, i.e. the one that got
  7. ** the icon(s) dropped on it.
  8. */
  9.  
  10. SAVEDS ASM LONG AppMsgFunc(REG(a2) APTR obj, REG(a1) struct AppMessage **x)
  11. {
  12.     struct WBArg *ap;
  13.     struct AppMessage *amsg = *x;
  14.     int i;
  15.     static char buf[256];
  16.     char *b=buf;
  17.  
  18.     for (ap=amsg->am_ArgList,i=0;i<amsg->am_NumArgs;i++,ap++)
  19.     {
  20.         NameFromLock(ap->wa_Lock,buf,sizeof(buf));
  21.         AddPart(buf,ap->wa_Name,sizeof(buf));
  22.         DoMethod(obj,MUIM_List_Insert,&b,1,MUIV_List_Insert_Bottom);
  23.     }
  24.  
  25.     return(0);
  26. }
  27.  
  28.  
  29. /*
  30. ** Having a function instead of a macro saves some code.
  31. */
  32.  
  33. APTR MakeLV(VOID)
  34. {
  35.     return(
  36.         ListviewObject,
  37.             MUIA_Listview_Input, FALSE,
  38.             MUIA_Listview_List , ListObject,
  39.                 ReadListFrame,
  40.                 MUIA_List_ConstructHook, MUIV_List_ConstructHook_String,
  41.                 MUIA_List_DestructHook , MUIV_List_DestructHook_String ,
  42.                 End,
  43.             End
  44.     );
  45. }
  46.  
  47.  
  48. int main(int argc,char *argv[])
  49. {
  50.     APTR app,window;
  51.     ULONG signals;
  52.     BOOL running = TRUE;
  53.     APTR lv1,lv2,lv3;
  54.     static const struct Hook AppMsgHook = { { NULL,NULL },(VOID *)AppMsgFunc,NULL,NULL };
  55.  
  56.     init();
  57.  
  58.     app = ApplicationObject,
  59.         MUIA_Application_Title      , "AppWindowDemo",
  60.         MUIA_Application_Version    , "$VER: AppWindowDemo 10.11 (23.12.94)",
  61.         MUIA_Application_Copyright  , "©1992/93, Stefan Stuntz",
  62.         MUIA_Application_Author     , "Stefan Stuntz",
  63.         MUIA_Application_Description, "Show AppWindow Handling",
  64.         MUIA_Application_Base       , "APPWINDOWDEMO",
  65.  
  66.         SubWindow, window = WindowObject,
  67.             MUIA_Window_Title    , "Drop icons on me!",
  68.             MUIA_Window_ID       , MAKE_ID('A','P','P','W'),
  69.             MUIA_Window_AppWindow, TRUE,
  70.  
  71.             WindowContents, VGroup,
  72.                 Child, HGroup,
  73.                     Child, lv1 = MakeLV(),
  74.                     Child, lv2 = MakeLV(),
  75.                     End,
  76.                 Child, lv3 = MakeLV(),
  77.                 End,
  78.  
  79.             End,
  80.  
  81.         End;
  82.  
  83.     if (!app)
  84.         fail(app,"Failed to create Application.");
  85.  
  86.     DoMethod(window,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
  87.         app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  88.  
  89.  
  90. /*
  91. ** Call the AppMsgHook when an icon is dropped on a listview.
  92. */
  93.  
  94.     DoMethod(lv1,MUIM_Notify,MUIA_AppMessage,MUIV_EveryTime,
  95.         lv1,3,MUIM_CallHook,&AppMsgHook,MUIV_TriggerValue);
  96.  
  97.     DoMethod(lv2,MUIM_Notify,MUIA_AppMessage,MUIV_EveryTime,
  98.         lv2,3,MUIM_CallHook,&AppMsgHook,MUIV_TriggerValue);
  99.  
  100.     DoMethod(lv3,MUIM_Notify,MUIA_AppMessage,MUIV_EveryTime,
  101.         lv3,3,MUIM_CallHook,&AppMsgHook,MUIV_TriggerValue);
  102.  
  103.  
  104. /*
  105. ** When we're iconified, the object lv3 shall receive the
  106. ** messages from icons dropped on our app icon.
  107. */
  108.  
  109.     set(app,MUIA_Application_DropObject,lv3);
  110.  
  111.  
  112. /*
  113. ** Input loop...
  114. */
  115.  
  116.     set(window,MUIA_Window_Open,TRUE);
  117.  
  118.     while (running)
  119.     {
  120.         switch (DoMethod(app,MUIM_Application_Input,&signals))
  121.         {
  122.             case MUIV_Application_ReturnID_Quit:
  123.                 running = FALSE;
  124.                 break;
  125.         }
  126.  
  127.         if (running && signals) Wait(signals);
  128.     }
  129.  
  130.     set(window,MUIA_Window_Open,FALSE);
  131.  
  132. /*
  133. ** Shut down...
  134. */
  135.  
  136.     fail(app,NULL);
  137. }
  138.